package org.kl.auditsupervision.service.fnd;

 

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.kl.auditsupervision.entity.fnd.ZgCsNop;
import org.kl.auditsupervision.repository.fnd.ZgCsNopDao;
import org.kl.bf.entity.BusinessEntity;
import org.kl.bf.service.BasicService;
import org.kl.bf.service.ServiceException;
import org.kl.bf.utils.BasicConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional
public class ZgCsNopService extends BasicService<ZgCsNop> {
	@Autowired
	private ZgCsNopDao zgCsNopDao;
	
	public List<ZgCsNop> findByAuditProDtlNopId(String auditProDtlNopId){
		return zgCsNopDao.findByAuditProDtlNopId(auditProDtlNopId);
	}
	
	public String multiDelete(String ids) {
		String[] idArray = StringUtils.split(ids, ",");
		int i = 0;
		for (String id : idArray) {
			if (StringUtils.isNotBlank(id)) {
				ZgCsNop zgCsNop = basicDao.findOne(id);
				if(zgCsNop.getAuditProDtlNop().getConfirmFlag().equals(BasicConstants.CONFIRM_STATUS_Draft)){
					basicDao.delete(id);
					i++;
				}else{
					 throw new ServiceException("该项目已确认，无法删除!");
				}
				
			}
		}
		return "成功删除" + i + "条记录";
	}
}
